﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using XDesigner.ORM;

namespace XDesigner.AppFramework.Test
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }


        public static System.Data.IDbConnection CreateConnection()
        {
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\""
                + System.IO.Path.Combine(Application.StartupPath, "AppFramework.mdb") + "\"";
            return conn;
        }

        private static ORMEngine myORM = null;
        public static ORMEngine ORM
        {
            get
            {
                if (myORM == null)
                {
                    myORM = new ORMEngine(CreateConnection());
                    myORM.Config.DebugMode = true;
                    myORM.Config.BufferLevel = ORMBufferLevel.Both;

                    myORM.OpenConnectionEvent += new ORMEventHandler(myORM_OpenConnectionEvent);
                }
                return myORM;
            }
        }

        static void myORM_OpenConnectionEvent(object sender, ORMEventArgs args)
        {
            args.Result = CreateConnection();
        }

    }
}